var app = getApp()
import * as appConfig from "../../../app-config.js";
import * as util from "../../../utils/util.js"

Page({

  data: {
    id: '',
    name: "",
    phone: "",
    password: ""

  },
  onLoad: function(options) {
    console.log(options)
    this.setData({
      name: options.name,
      phone: options.num,
      password: options.password,
      id: options.id
    })
  },

  changPswTap: function() {
    this.changeAccount();

  },

  //修改账号账号
  changeAccount: function() {
    var that = this;
    var password = this.data.password;
    if (password.length < 6) {
      wx.showToast({
        title: '密码至少6位',
        icon: "none"
      })
      return
    }

    app.getMemInfo().then(res => {
      var agentId = res.data.agentId;
      var url = '/wx_app/agent/account/add';
      var data = {
        agentId: agentId,
        id: this.data.id,
        name: this.data.name,
        phone: this.data.phone,
        password: password
      }
      app.request(url, data, 'GET').then(res => {
        console.log(res)
        this.changeSuccess(res);
      })
    })

  },
  changeSuccess:function(){
    wx.navigateBack({
      url: 'shopAccount',
    })
  },

  //删除用户
  deleteAccountTap: function() {

    var url = "/wx_app/agent/account/del";
    var data = {
      accountId: this.data.id
    }
    app.request(url, data, 'GET').then(res => {
      console.log(res)
      this.delSuccess(res);
    })
   
  },
  delSuccess: function() {
    wx.navigateBack({
      url: 'shopAccount',
    })
  },

  //获取账号姓名
  getNameValue: function(e) {
    this.setData({
      name: e.detail.value
    })
  },

  //获取手机号
  getPhoneValue: function(e) {
    this.setData({
      phone: e.detail.value
    })
  },


  getPswValue: function(e) {
    this.setData({
      password: e.detail.value
    })
  },


})